Attribute VB_Name = "modGetSpecialFolders"
Private Const csidl_desktop = &H0
Private Const csidl_programs = &H2
Private Const csidl_controls = &H3
Private Const csidl_printers = &H4
Private Const csidl_personal = &H5
Private Const csidl_favorites = &H6
Private Const csidl_startup = &H7
Private Const csidl_recent = &H8
Private Const csidl_sendto = &H9
Private Const csidl_bitbucket = &HA
Private Const csidl_startmenu = &HB
Private Const csidl_desktopdirectory = &H10
Private Const csidl_drives = &H11
Private Const csidl_network = &H12
Private Const csidl_nethood = &H13
Private Const csidl_fonts = &H14
Private Const csidl_templates = &H15

Private Const max_path = 260

Enum specialFolders
    desktop = &H0
    programs = &H2
    Controls = &H3
    Printers = &H4
    persional = &H5
    favorites = &H6
    startup = &H7
    recent = &H8
    sendto = &H9
    bitbucket = &HA
    startmenu = &HB
    desktopDirectory = &H10
    dirves = &H11
    NetWork = &H12
    nethood = &H13
    Fonts = &H14
    templates = &H15
End Enum

Private Type shitemid
    cb As Long
    abid As Byte
End Type

Private Type itemidlist
    mkid As shitemid
End Type

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nfolder As Long, pidl As itemidlist) As Long
Private Declare Function SHGetPathFromIdlist Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszpath As String) As Long

Public Function GetSpecialfolder(folderType As specialFolders) As String
    Dim r As Long
    Dim IDL As itemidlist
    'Get the special folder
    r = SHGetSpecialFolderLocation(100, folderType, IDL)
    If r = noerror Then
        'Create a buffer
        path$ = Space$(512)
        'Get the path from the IDList
        r = SHGetPathFromIdlist(ByVal IDL.mkid.cb, ByVal path$)
        'Remove the unnecessary chr$(0)'s
        GetSpecialfolder = Left$(path, InStr(path, Chr$(0)) - 1)
        Exit Function
    End If
    GetSpecialfolder = ""
End Function

